package com.xyh.imdemo.utils;

import ch.qos.logback.core.util.FileUtil;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： com.xyh.imdemo.utils
 * @类名称：FileMerge
 * @创建人：YIHANG.XU
 * @创建时间：2021/9/910:50 下午
 * @修改人：YIHANG.XU
 * @修改时间：2021/9/910:50 下午
 * @修改备注：
 * @Copyright
 */
public class FileMerge {
    public static void main(String[] args) throws IOException {
        String filePath = "/Users/xuyihang/Downloads/voide/path";
        List<String> files = getFiles(filePath);
        BufferedWriter bw = new BufferedWriter(new FileWriter("/Users/xuyihang/Downloads/voide/mk/aa.mp4"));
        for (int i = 0; i < files.size(); i++) {
            File file = new File(files.get(i));
            BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                bw.write(line);
                bw.newLine();
            }
            bufferedReader.close();
        }
        bw.close();


    }

    public static List getFiles(String path) {
        List list = new ArrayList();
        File[] files = new File(path).listFiles();
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                List node = getFiles(files[i].getPath());
                list.addAll(node);
            } else {
                list.add(files[i].getPath());
            }
        }
        return list;
    }
}
